home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 2.7 KB | 76 lines | [TEXT/CWIE] |
- // MasterPointer.h
-
- #ifndef MasterPointer_h
- #define MasterPointer_h
-
- #ifndef Integers_h
- #include "Integers.h"
- #endif
- #ifndef Assert_h
- #include "Assert.h"
- #endif
-
- class MasterPointer
- {
- private:
- void *pointer;
-
- // These don't exist
- MasterPointer( const MasterPointer& );
- void operator=( const MasterPointer& );
-
- MasterPointer() {}
-
- static void ThrowAllocationError( OSErr, void * );
-
- public:
- enum SystemHeap { systemHeap };
- enum Temporary { temporary };
-
- static MasterPointer *MakeEmpty() { return new MasterPointer; }
- static MasterPointer *Make( uint32 size ) { return new( size ) MasterPointer; }
- static MasterPointer *MakeEmptyInSystemHeap() { return new( systemHeap ) MasterPointer; }
- static MasterPointer *MakeInSystemHeap( uint32 size ) { return new( size, systemHeap ) MasterPointer; }
- static MasterPointer *MakeTemporary( uint32 size ) { return new( size, temporary ) MasterPointer; }
-
- void *operator new( uint32 pointerSize );
- void *operator new( uint32 pointerSize, uint32 blockSize );
- void *operator new( uint32 pointerSize, SystemHeap );
- void *operator new( uint32 pointerSize, uint32 blockSize, SystemHeap );
- void *operator new( uint32 pointerSize, uint32 blockSize, Temporary );
- void operator delete( void * );
-
- void *Pointer() const { return pointer; }
- ::Ptr Ptr() const { return static_cast<::Ptr>( pointer ); }
- ::Handle Handle() const { return reinterpret_cast<::Handle>( const_cast<void **>(&pointer) ); }
-
- bool IsEmpty() const { return pointer == 0; }
- void BeEmpty() { EmptyHandle( Handle() ); }
- void Allocate( uint32 size ) { Assert( IsEmpty() ); ReallocateHandle( Handle(), size ); }
-
- uint32 Size() const { Assert( !IsEmpty() ); return GetHandleSize( Handle() ); }
- void SetSize( uint32 newSize ) { Assert( !IsEmpty() ); SetHandleSize( Handle(), newSize ); }
-
- SignedByte State() const { return HGetState( Handle() ); }
- void SetState( SignedByte state ) { HSetState( Handle(), state ); }
-
- void Lock() { HLock( Handle() ); }
- void Unlock() { HUnlock( Handle() ); }
-
- void AllowPurging() { HPurge( Handle() ); }
- void ForbidPurging() { HNoPurge( Handle() ); }
-
- void BeResource() { HSetRBit( Handle() ); }
- void BeNotResource() { HClrRBit( Handle() ); }
-
- static MasterPointer& At( ::Handle h ) { return *reinterpret_cast<MasterPointer *>( h ); }
- static MasterPointer& MasterPointerFor( void *p ) { return At( RecoverHandle( static_cast<::Ptr>(p) ) ); }
-
- void MoveHigh() { MoveHHi( Handle() ); }
- void LockHigh() { HLockHi( Handle() ); }
-
- THz Zone() const { return HandleZone( Handle() ); }
- };
-
- #endif
-